package com.leve.control.mapper;

import com.leve.control.domain.CuserDevice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author whongyu
 * @create by 2019/6/14
 */
@Repository
public interface CuserDeviceMapper {

    @Select(" select a.id,b.mobile,a.remark_name,a.device_id,a.permission from ims_levepower_iot_cuser_device a left join ims_levepower_iot_cuser b on a.cuser_id=b.cuser_id where a.device_id=#{deviceId} and a.permission=#{permission} ")
    List<CuserDevice> queryDeviceByDeviceId(int deviceId,int permission);


    @Update("<script>" +
            "update ims_levepower_iot_cuser_device " +
            "<set>" +
            "<if test=\"cuserId != null\">`cuser_id` = #{cuserId}, </if>" +
            "<if test=\"deviceId != null\">`device_id` = #{deviceId}, </if>" +
            "<if test=\"remarkName != null\">`remark_name` = #{remarkName}, </if>" +
            "<if test=\"permission != null\">`permission` = #{permission}</if>" +
            "</set>" +
            " where id = #{id}" +
            "</script>")
    int update(CuserDevice cuserDevice);

    @Delete("delete from ims_levepower_iot_cuser_device where id = #{id}")
    int remove(int id);

    @Insert("insert into ims_levepower_iot_cuser_device(`cuser_id`, `device_id`, `remark_name`, `permission`) values(#{cuserId}, #{deviceId}, #{remarkName}, #{permission})")
    int add(CuserDevice cuserDevice);
}
